//
//  ByBetCirclesView.m
//  caipiao_ios
//
//  Created by mc on 2018/8/14.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByBetCirclesView.h"

@implementation ByBetCirclesView

- (UIColor *)themeColor{
    if (_themeColor) {
        _themeColor = BY_THEME_COLOR;
    }
    return _themeColor;
}


- (id)init{
    self = [super init];
    if (self) {
        UILabel *titleLabel = [[UILabel alloc] init];
        [self addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(10);
            make.top.equalTo(self).offset(5);
            make.height.mas_equalTo(@15);
            make.width.mas_equalTo(@45);
        }];
        titleLabel.text = @"红球:";
        titleLabel.font = FONT(13);
        titleLabel.textColor = [UIColor blackColor];
        titleLabel.textAlignment = NSTextAlignmentLeft;
        self.titleLabel = titleLabel;
    }
    return self;
}


- (void)setDataArray:(NSMutableArray *)dataArray{
    _dataArray = dataArray;
    
    CGFloat magin = 10;
    NSInteger count = 6;
    CGFloat width = (SCREEN_WIDTH - 20 - 85 - 55 - magin * count) / count;
    
    if (width < 21) {
        count = 5;
        width = (SCREEN_WIDTH - 20 - 85 - 55 - magin * count) / count;
        
    }
    
    if (width < 21) {
        count = 4;
        width = (SCREEN_WIDTH - 20 - 85 - 55 - magin * count) / count;
    }
    for (int i = 0;i < _dataArray.count; i++) {
        ByNetModel *netModel = [_dataArray objectAtIndex:i];
        UILabel *valueLabel = [[UILabel alloc] initWithFrame:CGRectMake(55 + i % count * (width + magin), i / count * (width + magin), width, width)];
        [self addSubview:valueLabel];
        valueLabel.layer.cornerRadius = width / 2.0;
        valueLabel.text = netModel.title;

        
        valueLabel.tag = 100 + i;
        valueLabel.font = FONT(14);
        valueLabel.textAlignment = NSTextAlignmentCenter;
        valueLabel.layer.masksToBounds = YES;
        
        valueLabel.textColor = [UIColor whiteColor];
        valueLabel.backgroundColor = _themeColor;
        ;
        
    }
    
    
}

+ (CGFloat)getHeightWithDataArray:(NSMutableArray *)dataArray{
    
   
    CGFloat magin = 10;
    
    NSInteger count = 6;
    CGFloat width = (SCREEN_WIDTH - 20 - 85 - 55 - magin * count) / count;
    
    if (width < 21) {
        count = 5;
        width = (SCREEN_WIDTH - 20 - 85 - 55 - magin * count) / count;
        
    }
    
    if (width < 21) {
        count = 4;
        width = (SCREEN_WIDTH - 20 - 85 - 55 - magin * count) / count;
    }
    
    CGFloat height = (width + magin) * ((dataArray.count - 1) / count  + 1);;
    return height;
}

@end
